/**
 * 获取用户管理范围
 * @param {*} user 
 */
export const findUserManagerScope =  (user) =>{
    if (!user instanceof Object) {
        return null
    }
    if (user.isadmin) { // 管理员
        return {depart: user.scope, type: 'org', isadmin: true, isleader: false}
    } else {
        if (user.department) {
            let isleader = false
            let depart = null
            user.department.forEach(item => {
                if (item.isleader) {
                    isleader = true
                    depart = item.id
                }
            });
            if (isleader) { // 部门负责人
                return {depart: depart, type: 'org', isadmin: false, isleader: true}
            } else {
                return {depart: user.maindepartment, type: 'user', isadmin: false, isleader: false, userid: user.userid}
            }
        }
    }
}

/**
 * 修正children子节点
 * @param {*} data
 * @returns
 */
export function fixChildren (data) {
    return data.map(item => {
      if (!item.children || item.children.length === 0) {
        delete item.children
      } else {
        item.children = fixChildren(item.children)
      }
      return item
    })
}
